setwd("~/accept_decline")
df = readRDS("train.rds")

profile_info = function(x)
{
	NA_cnt = sum(is.na(x))
	NA_pct = mean(is.na(x))
	NA_avg = mean(train$loss[is.na(x)] > 0)
	c(NA_cnt, NA_pct, NA_avg, length(unique(x)))
}
nas = rep(NA, 778)
prof = data.frame(NA_cnt=nas, NA_pct=nas, NA_avg=nas, unique_vals=nas)
for(i in 2:779) prof[i-1,] = profile_info(df[,i])
prof = data.frame(var_name = names(df)[2:779], prof)

f_val=3
i=f_val+1
profile_info(train[,i])
breaks = unique(quantile(train[,i], seq(0, 1, .005), na.rm=T))
f = cut(train[,i], breaks, include.lowest=T)

plot(tapply(ifelse(train$loss>0,1,0), f, mean), type="b")


#variables with only 1 value - not useful
summary(df$f33)
summary(df$f34)
summary(df$f35)
summary(df$f37)
summary(df$f38)
summary(df$f700)
summary(df$f701)
summary(df$f702)
summary(df$f736)
summary(df$f764)
summary(df$f678) #all zeros except for 1 NA

summary(as.factor(df$f776))
summary(as.factor(df$f777))

tapply(df$loss>0, as.factor(df$f776), mean)
tapply(df$loss, as.factor(df$f776), mean)

tapply(df$loss>0, as.factor(df$f777), mean)
tapply(df$loss, as.factor(df$f777), mean)

